import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginView from '../views/LoginView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: LoginView,
    meta: { auth: true }
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path:'/login',
    component: LoginView,
    meta: { auth: true }
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/AboutView.vue'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
  },
  {
    path:'/admin',
    name: 'admin',
    component: () => import('../views/AdminView.vue'),
  },
  {
    path:'/log',
    name: 'log',
    component: () => import('../views/LogView.vue'),
  },
  {
    path:'/search',
    name: 'search',
    component: () => import('../views/SearchView.vue'),
  },
  {
    path:'/user',
    name: 'user',
    component: () => import('../views/UserView.vue'),
  },
  {
    path: '/aboutUs',
    name: 'aboutUs',
    component: () => import('../views/AboutUsView.vue'),
    meta: { auth: true }
  },
  {
    path: '/reset-password',
    component: () => import('../views/ResetPassword.vue'),
    meta: { auth: true }
  },
  {
    path: '/test',
    component: () => import('../components/test.vue'),
    meta: { auth: true }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g
  const isChunkLoadFailed = error.message.match(pattern);
  if(isChunkLoadFailed) {
    location.reload;
  }
})

export default router
